﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;


/// <summary>
/// 带弧度 子弹
/// </summary>
public class CurveGun : HEnemyGun
{
    public int MaxCountPerPoint = 5;//一个发炮点发射一次的数量
    public float angle = 90;//发炮角度

    protected int fireCount;
    protected virtual void Start()
    {
        fireCount = MaxCountPerPoint;
    }

    public override void Fire()
    {
        if (CanFire(lastFireTime))
        {
            lastFireTime = Time.time;
            fireCount = fireCount == MaxCountPerPoint ? MaxCountPerPoint + 1 : MaxCountPerPoint;

            FireOnePoint(0);
        }
    }

    protected virtual void FireOnePoint(int index)
    {
        Transform firepoint = firePoints[index];
        for (int i = 0; i < fireCount; i++)
        {
            Vector3 pos = CaculPos(firepoint);
            Quaternion rot = CaculRot(firepoint, fireCount, i);
            CreateBullet(pos, rot);
        }
    }
    protected virtual Vector3 CaculPos(Transform firepoint)
    {
        return firepoint.position;
    }

    protected virtual Quaternion CaculRot(Transform firepoint,int total,int index)
    {
        var localpoint = RoleManager.Instance.localPlayer.transform.position;
        var target = Vector3.Normalize(localpoint - firepoint.position);
        firepoint.up = target;
        return firepoint.rotation*Quaternion.Euler(0, 0, (index - total / 2f) * angle/ total);
    }

}
